﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace Bilyteam_Website.Admin
{
    public partial class ParentCategoryManager : System.Web.UI.Page
    {
        SqlConnection conn = new SqlConnection();
        SqlCommand cmd = new SqlCommand(); 

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

            }
            lbTest.Visible = false;
        }

        protected void btInsert_Click(object sender, EventArgs e)
        {
            Category cate = new Category();

            cate.CategoryName = txtCategoryName.Text;
            cate.Link = txtLink.Text;
            cate.Parrent = txtParrent.Text;
            cate.Type = txtType.Text;
            cate.Status = 0;

            conn.ConnectionString = ConfigurationManager.ConnectionStrings["PROJECT"].ConnectionString;
            conn.Open();
            cmd.Connection = conn;
            cmd.CommandText = "insert into Categories values(@CategoryName , @Link , @Parrent , @Type , @Status)";
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.Add("@CategoryName", SqlDbType.NVarChar);
            cmd.Parameters.Add("@Link", SqlDbType.NVarChar);
            cmd.Parameters.Add("@Parrent", SqlDbType.NVarChar);
            cmd.Parameters.Add("@Type", SqlDbType.NVarChar);
            cmd.Parameters.Add("@Status", SqlDbType.Int);

            cmd.Parameters[0].Value = cate.CategoryName;
            cmd.Parameters[1].Value = cate.Link;
            cmd.Parameters[2].Value = cate.Parrent;
            cmd.Parameters[3].Value = cate.Type;
            cmd.Parameters[4].Value = cate.Status;
            int result = cmd.ExecuteNonQuery();
            if (result == 1)
            {
                lbTest.Visible = true;
                lbTest.Text = "Successfull";


            }
            else
            {
                lbTest.Visible = true;
                lbTest.Text = "failed";
            }
            conn.Close();
            txtCategoryName.Text = "";
            txtLink.Text = "";
        }
        protected void btCancel_Click(object sender, EventArgs e)
        {
            txtCategoryName.Text = "";
            txtLink.Text = "";
        }
    }
}